package com.milk.milkmedia.ui;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;

import com.milk.milkmedia.R;
import com.milk.milkmedia.api.ConstantField;


/**
 * Created by 微安 on 2015/10/11.
 */
public class WelcomeAcitvity extends Activity {

    private Handler mHandler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        mHandler = new Handler();
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                startFrame();
            }
        }, 500);
        finish();
    }

    private void startFrame() {
        SharedPreferences sharedPreferences = this.getSharedPreferences(ConstantField.SP_CONFIG,
                Context.MODE_PRIVATE);
        String version = null;
        String curVersion = null;
        try {
            version = getApplication().getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        curVersion = sharedPreferences.getString(ConstantField.SP_VERSION,ConstantField.APP_VERSION);
        if (version.equals(curVersion)) {
            Intent intent;
            intent = new Intent(this, HomePageActivity.class);
            startActivity(intent);
            finish();
        } else {
            Log.d(HomePageActivity.Tag, curVersion + "进入了" + version);
            intoGuideView();
        }

    }

    private void intoGuideView() {
        Intent intent = new Intent(this, GuideActivity.class);
        startActivity(intent);
    }

    @Override
    public void onBackPressed() {
    }
}
